import numpy as np
from matplotlib import pyplot as plt


def get_joint_name(i):
    joint = ['abad', 'hip', 'knee']
    leg = ['FR', 'FL', 'HR', 'HL']
    return leg[int(i / 3)], joint[i % 3]


def remap_index(i):
    leg = int(i / 3)
    joint = i % 3
    return joint * 4 + leg


def color_line(x, y, t, c0=[0.0, 0.5, 1.0, 1.0], c1=[1.0, 0.5, 0.0, 1.0]):
    t_norm = (t - t.min()) / (t.max() - t.min())
    for i in range(x.shape[0] - 1):
        c = [c0[j] * (1.0 - t_norm[i]) + c1[j] * t_norm[i] for j in range(4)]
        plt.plot(x[i:i+2], y[i:i+2], color=c)